import unittest

from parameterized import parameterized


from base import log
from page.page_app_login import PageAppLogin
from page.page_app_order import PageAppOrder
from util import GetDriver, read_json, write_json


class TestAppLogin(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = GetDriver.get_app_driver()
        self.app = PageAppLogin(self.driver)
        self.app_order = PageAppOrder(self.driver)

    def tearDown(self) -> None:
        self.driver.quit()

    @parameterized.expand(read_json("app_order.json", "order"))
    def test01_login(self, search_value, pwd, expect_text):
        try:
            self.app.page_app_login()
            nickname1 = self.app.page_app_nickname_text()
            print("会员ID:", nickname1)
            self.assertEqual(expect_text, nickname1)
            # 下订单
            self.app_order.page_app_order(search_value, pwd)
    #         获取订单编号
            order_no = self.app_order.page_app_text_no()
            print("订单编号：", order_no)
    # 记录订单编号
            write_json(order_no[5:])
            log.info("=======>app下单成功，订单编号为：{}".format(read_json("expect.json", "expect")[0][0]))
        except Exception as e:
            log.error(e)
            # 截图
            self.app_order.base_get_img()
            # 抛异常
            raise


